package com.example.spark.controller;

import com.example.spark.entity.User;
import com.example.spark.entity.result.CommonResult;
import com.example.spark.service.EnterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@CrossOrigin
@RestController
@RequestMapping("/user")
public class EnterController {
    @Autowired
    private EnterService enterService;

    //登录
    @GetMapping("/login")
    public CommonResult checkLogin(@RequestParam("username") String username,
                                   @RequestParam("password") String password) {

        return enterService.checkLogin(username, password);
    }

    //注册
    @PostMapping("/register")
    public CommonResult registerUser(@RequestBody User user) {

        return enterService.registerUser(user);
    }

    //图片
    @PutMapping("photos")
    public CommonResult addPhoto(@RequestParam MultipartFile file, @RequestParam Long id) throws IOException {

        return enterService.addPhoto(file, id);
    }

    //注销用户
    @DeleteMapping("deleteUser/{id}")
    public CommonResult deleteUser(@PathVariable Long id) {
        return enterService.updateUserFlag(id);
    }
}
